﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC
{
	public partial class LaySideAirTerminalLineForm : System.Windows.Forms.Form
	{
		public LaySideAirTerminalLineForm(HVACUserSetting uSetting)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
			this.userSetting = uSetting;
		}

		private void LaySideAirTerminalLineForm_Load(object sender, EventArgs e)
		{
			this.InitialUserSetting();
		}

		private void InitialUserSetting()
		{
			try
			{
				string[] sideAirTerminalLayInfo = this.userSetting.GetSideAirTerminalLayInfo();
				if (string.IsNullOrEmpty(sideAirTerminalLayInfo[1]))
				{
					this.hyTxtDistance.Text = "2500";
				}
				else
				{
					this.hyTxtDistance.Text = Convert.ToInt32(sideAirTerminalLayInfo[1]).ToString();
				}
				if (string.IsNullOrEmpty(sideAirTerminalLayInfo[3]) || sideAirTerminalLayInfo[3] == "0")
				{
					this.ckbByNumber.Checked = false;
				}
				else
				{
					this.ckbByNumber.Checked = true;
				}
				if (string.IsNullOrEmpty(sideAirTerminalLayInfo[4]))
				{
					this.upDownNum.Value = 1m;
				}
				else
				{
					this.upDownNum.Value = Convert.ToInt32(sideAirTerminalLayInfo[4]);
				}
				if (this.ckbByNumber.Checked)
				{
					this.upDownNum.Enabled = true;
				}
				else
				{
					this.upDownNum.Enabled = false;
				}
			}
			catch (Exception)
			{
				this.hyTxtDistance.Text = "2500";
				this.ckbByNumber.Checked = false;
				this.upDownNum.Value = 1m;
			}
		}

		private void rdoPickPoint_CheckedChanged(object sender, EventArgs e)
		{
		}

		private void ckbByNumber_CheckedChanged(object sender, EventArgs e)
		{
			if (this.ckbByNumber.Checked)
			{
				this.upDownNum.Enabled = true;
				return;
			}
			this.upDownNum.Enabled = false;
		}

		private void btnSure_Click(object sender, EventArgs e)
		{
			this.layParameter.BeBasePoint = true;
			this.layParameter.Distance = Convert.ToInt32(this.hyTxtDistance.Text);
			if (this.layParameter.Distance <= 200)
			{
				YJKMessageBox.Show("布置间距太小，无法进行布置");
				return;
			}
			this.layParameter.SideDistance = 0;
			this.layParameter.BeNum = this.ckbByNumber.Checked;
			this.layParameter.UpDownValue = Convert.ToInt32(this.upDownNum.Value);
			string[] texts = new string[]
			{
				"0",
				this.layParameter.Distance.ToString(),
				"0",
				(!this.layParameter.BeNum) ? "0" : "1",
				this.layParameter.UpDownValue.ToString()
			};
			try
			{
				this.userSetting.WriteSideAirTerminalInfo(texts);
			}
			catch (Exception)
			{
			}
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private HVACUserSetting userSetting;

		public LaySideParameter layParameter = new LaySideParameter();
	}
}
